<?php
// $Id$

$config_dir    =  dirname(dirname(dirname(__FILE__))) . "/config/";
require_once( $config_dir . "config.controller.inc.php");
/**
 * Controller_Img 控制器
 */
class Controller_Img extends Controller_Abstract
{

	function actionIndex()
	{
        // 为 $this->_view 指定的值将会传递数据到视图中
		# $this->_view['text'] = 'Hello!';
	}
    
    function actionUploadImgs()
    {
        $form = new Form_UploadImgs(url('img/uploadimgs'));
        if ( $this->_context->isPOST() && $form->validate($_POST) )
        {
            try
            {
                $values = $form->values();
                if ($values["img_type"] == "goods")
                {
                    $img_path_base = IMG_GOODS_PATH;
                }
                else if ($values["img_type"] == "act")
                {
                    $img_path_base = IMG_ACT_PATH;
                }
                else
                {
                    $img_path_base = IMG_UPLOAD_PATH;
                }
                foreach($_FILES["imgs"]["error"] as $key=>$err)
                {
                    if (UPLOAD_ERR_OK == $err)
                    {
                        $date_path = date("Y-M");
                        $img_file_path = $img_path_base . $date_path . "/";
                        if ($img_file_path != '.' && $img_file_path != '..' && !is_dir($img_file_path))
                        {
                            passthru("mkdir -p $img_file_path >/dev/null");
                        }
                        $img_file_path = $img_file_path . $_FILES["imgs"]["name"][$key];  
                        move_uploaded_file($_FILES["imgs"]["tmp_name"][$key], $img_file_path);
                        $img_root_path = IMG_ROOT_PATH;
                        echo str_replace("$img_root_path", "http://localhost/img/", $img_file_path) . "<br/>";
                    }
                }
            }
            catch (Exception $ex)
            {
                print_r($ex);
                exit();
            }
        }
    }
}


